/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Specialized;
using System.Collections.Generic;
using Xceed.Silverlight.Data.Stats;

namespace Xceed.Silverlight.Data
{
  internal class DataChangedEventArgs : EventArgs
  {
    internal DataChangedEventArgs()
    {
    }

    public DataChangedAction Action
    {
      get;
      private set;
    }

    public object NewItem
    {
      get;
      private set;
    }

    public object OldItem
    {
      get;
      private set;
    }


    public SourcePosition RemovePosition
    {
      get;
      private set;
    }

    public SourcePosition NewCurrentPosition
    {
      get;
      private set;
    }

    public IEnumerable<Tuple<object, object>> LoadedItems
    {
      get;
      private set;
    }

    public bool UpdateItems
    {
      get;
      private set;
    }

    public ItemChangedInfo ItemChangedInfo
    {
      get;
      private set;
    }

    public StatParameters StatParameters
    {
      get;
      private set;
    }


    internal DataChangedEventArgs( DataChangedAction action )
    {
      if(  action != DataChangedAction.Reset )
        throw new ArgumentException( "Only the Reset action is supported by this constructor.", "action" );

      this.Action = action;
    }

    internal DataChangedEventArgs( DataChangedAction action, object item )
    {
      if( action != DataChangedAction.Add )
        throw new ArgumentException( "Only the Add action is supported by this constructor.", "action" );

      this.Action = action;

      this.NewItem = item;
      this.OldItem = null;
    }

   internal DataChangedEventArgs( DataChangedAction action, object item, SourcePosition removePosition, SourcePosition newCurrentPosition )
    {
      if( action != DataChangedAction.Remove )
        throw new ArgumentException( "Only the Remove action is supported by this constructor.", "action" );

      this.Action = action;

      this.NewItem = null;
      this.OldItem = item;
      this.RemovePosition = removePosition;
      this.NewCurrentPosition = newCurrentPosition;
    }

     internal DataChangedEventArgs( DataChangedAction action, object newItem, object oldItem )
    {
      if( action != DataChangedAction.Replace )
        throw new ArgumentException( "Only the Replace action is supported by this constructor.", "action" );

      this.Action = action;
      this.NewItem = newItem;
      this.OldItem = oldItem;
    }

    public DataChangedEventArgs(DataChangedAction action, IList<Tuple<object,object>> loadedItems, bool updateItems)
    {
      if( action != DataChangedAction.ItemsLoaded )
        throw new ArgumentException( "Only the ItemsLoaded action is supported by this constructor.", "action" );

      this.Action = action;
      this.LoadedItems = loadedItems;
      this.UpdateItems = updateItems;
    }

    internal DataChangedEventArgs( DataChangedAction action, StatParameters statParameters, StatResults newStatResult, StatResults oldStatResult )
    {
      if( action != DataChangedAction.StatLoaded )
        throw new ArgumentException( "Only the StatLoaded action is supported by this constructor.", "action" );

      if( statParameters == null )
        throw new ArgumentNullException( "statParameters" );

      if( newStatResult == null )
        throw new ArgumentNullException( "newStatResult" );

      if( oldStatResult == null )
        throw new ArgumentNullException( "oldStatResult" );

      this.Action = action;
      this.StatParameters = statParameters;
      this.NewItem = newStatResult;
      this.OldItem = oldStatResult;
    }    

    public DataChangedEventArgs( ItemChangedInfo itemChangedInfo )
    {
      if( itemChangedInfo == null )
        throw new ArgumentNullException( "itemChangedInfo" );

      this.Action = DataChangedAction.ItemChanged;
      this.ItemChangedInfo = itemChangedInfo;
    }

    internal DataChangedEventArgs( 
      DataChangedAction action, 
      object newItem, 
      object oldItem, 
      SourcePosition removePosition, 
      SourcePosition newCurrentPosition, 
      ItemChangedInfo itemChangedInfo )
    {
      this.Action = action;
      this.NewItem = newItem;
      this.OldItem = oldItem;
      this.RemovePosition = removePosition;
      this.NewCurrentPosition = newCurrentPosition;
      this.ItemChangedInfo = itemChangedInfo;
    }
  }
}
